package com.zhiyueshufang.adapter

import android.util.SparseArray
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.zhiyueshufang.fragment.IndexFragment
import com.zhiyueshufang.fragment.MineFragment
import com.zhiyueshufang.fragment.TaskFragment

class ViewPagerFragmentStateAdapter(fragmentActivity: FragmentActivity) :
    FragmentStateAdapter(fragmentActivity) {

    private val fragments: SparseArray<Fragment> = SparseArray()

    init {
        fragments.put(0, IndexFragment())
        fragments.put(1, TaskFragment())
        fragments.put(2, MineFragment())
    }

    override fun getItemCount(): Int {
        return fragments.size()
    }

    override fun createFragment(position: Int): Fragment {
        return fragments[position]
    }
}